<template>
  <div class="hello">
    {{fullName}}
    <br>
    {{count}} <span style="color: red;font-size: 20px">{{flag}}</span>
    <br>
    <button @click="add">+</button>
    <button @click="desc">-</button>
    <br> <br>
    <button @click="asyncAdd">asyncAdd</button>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  computed:{
    count(){
      return this.$store.state.count;
    },
    flag(){
      return this.$store.getters.flag;
    },
    fullName(){
      return this.$store.getters.fullName;
    }
    /*firstName(){
      return this.$store.state.firstName;
    },
    lastName(){
      return this.$store.state.lastName;
    },
    fullName(){
      return `${this.firstName}-${this.lastName}`
    }*/
    /*flag(){
      return this.count % 2 === 0 ? "偶":"奇"
    }*/
  },
  methods:{
    add(){
      this.$store.commit({
        type:"add",
        num:2,
        text:"加-"
      })
    },
    desc(){
      this.$store.commit("desc",{num:1,text:"减"})
    },
    asyncAdd(){
      this.$store.dispatch("asyncAdd",4)
    }
  }
}
</script>

<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
